package solution;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-19
 * Time: 15:34
 */

//https://leetcode.cn/problems/palindrome-number/submissions/396279814/
public class Solution1 {

    public boolean isPalindrome(int x) {
        if (x == 0) {
            return true;
        }
        //负数和个数为0的不可能为回文数（负号，最高位不能为0）
        if (x < 0 || x % 10 == 0) {
            return false;
        }
        int revert = 0;
        //只需遍历一半即可判断是否为回文数
        while (x > revert) {
            revert = revert * 10 + x % 10;
            x /= 10;
        }
        //位数为偶数相等，奇数减少一位后相等
        return x == revert || x == revert / 10;
    }

}
